package cn.ylz.ylmall.content.dao.persist.repository.impl;

import cn.ylz.ylmall.content.dao.persist.mapper.CommentMapper;
import cn.ylz.ylmall.content.dao.persist.repository.ICommentRepository;
import cn.ylz.ylmall.content.pojo.entity.Comment;
import cn.ylz.ylmall.content.pojo.vo.CommentListItemVO;
import cn.ylz.ylmall.content.pojo.vo.CommentStandardVO;
import cn.ylz.ylmall.content.pojo.vo.CountVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

@Slf4j
@Repository
public class CommentRepositoryImpl implements ICommentRepository {
    @Autowired
    private CommentMapper commentMapper;

    /**
     * 发表评论
     * @param comment
     * @return
     */
    @Override
    public int insert(Comment comment) {
        log.debug("开始执行[插入内容]...");
        return commentMapper.insert(comment);
    }

    /**
     * 根据评论id查询 评论
     * @param id
     * @return
     */
    @Override
    public CommentStandardVO getStandardById(Long id) {
        log.debug("开始执行[根据ID查询内容]...");
        return commentMapper.getStandardById(id);
    }

    /**
     * 根据评论id删除评论
     * @param id
     * @return
     */
    @Override
    public int deleteById(Long id) {
        log.debug("开始执行[根据ID删除内容]...");
        return commentMapper.deleteById(id);
    }

    @Override
    public List<CommentListItemVO> listByContentId(Long contentId) {
        log.debug("开始执行【查询文章列表】的数据访问");
        List<CommentListItemVO> list = commentMapper.listByContentId(contentId);
        if(list.size() == 0){
            log.debug("查询文章评论列表为空");
        }
       return list;
    }

    @Override
    public CountVO countByContentId(Long contentId) {
       return commentMapper.countByContentId(contentId);
    }

    @Override
    public List<CommentStandardVO> getChild(Long id) {
        return commentMapper.getChild(id);
    }

    @Override
    public List<CommentListItemVO> listByParentId(Long id) {
        return commentMapper.listByParentId(id);
    }
}
